package sn.gandal.mobile.kalpet.data.server;


import java.io.IOException;
import java.util.Date;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;



import android.content.Context;

import sn.gandal.mobile.kalpet.data.entities.Account;
import sn.gandal.mobile.kalpet.utils.PropertiesKey;
import sn.gandal.mobile.kalpet.utils.PropertiesUtils;

public class ServerResourcesManager extends IDataRemoteAcces 
//implements IServerResourcesManager 
{

	private static ServerResourcesManager instance;
	private static IDataRemoteAcces helper;
	Context context;

	public static  void init(Context cx) {
		if (null == instance) {
			instance = new ServerResourcesManager(cx);
		}
		if (null == helper) {
			if (PropertiesUtils.getBoolean(cx, PropertiesKey.DATA_ACCES_MODE_MOCK)) {
				helper = ServerMockHelper.getInstance();
			} else {
				helper = ServerRessourcesHelper.getInstance();
			}
		}

	}

	public ServerResourcesManager(Context cx) {
		context = cx;
	}

	public static ServerResourcesManager getInstance() {
		return instance;
	}

	

	@Override
	public String authServer(String codeSecret, String numeroCli) {
		/*
		 * String url= URL_GUICHET+GUICHET_RESOURCES; HttpClient httpclient =
		 * new DefaultHttpClient(); HttpGet request=new HttpGet(url);
		 * request.setHeader("content-type", "application/JSON"); HttpResponse
		 * response = httpclient.execute(request); StatusLine statusLine =
		 * response.getStatusLine(); String responseString =null;
		 * if(statusLine.getStatusCode()== HttpStatus.SC_OK){
		 * ByteArrayOutputStream out = new ByteArrayOutputStream();
		 * response.getEntity().writeTo(out); out.close(); responseString =
		 * out.toString(); //..more logic } else{ //Closes the connection.
		 * response.getEntity().getContent().close(); throw new
		 * IOException(statusLine.getReasonPhrase()); }
		 */
		return helper.authServer(ServerResourcesPath.URL_GUICHET,
				ServerResourcesPath.GUICHET_RESOURCES);
	}

	@Override
	public String get(String addr, String path, Map params)
			throws ClientProtocolException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getUserData(String numero, String code) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getFriendsList(String numeroClient, String userPhoneToken,
			Date dateRefresh) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getAllHistorics(String numeroClient, String userPhoneToken,
			Date dateRefresh) {
		// TODO Auto-generated method stub
		return helper.getAllHistorics(numeroClient, userPhoneToken, dateRefresh);
	}

	@Override
	public String put(String addr, String path, Map params)
			throws ClientProtocolException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String delete(String addr, String path, Map params)
			throws ClientProtocolException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getAccountById(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String saveAccount(Account account) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String saveCompteCredit() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String saveCompteCarte() {
		// TODO Auto-generated method stub
		return null;
	}

}
